#include<bits/stdc++.h>
using namespace std;

int main() {
    int T;
    cin >> T;
    while (T--) {
        int n;
        cin >> n;
        vector<int> v(n);
        string s;
        for (int i = 0; i < n; i++) cin >> v[i];
        cin >> s;

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            if (s[i] == '>') {
                if (v[i] <= 0) {
                    cnt++;
                    v[i]=1;
                }
            } else if (s[i] == '<') {
                if (v[i] >= 0) {
                    cnt++;
                    v[i]=-1;
                }
            }
        }
        for (int i = 1; i < n; i++) {
            if (s[i] == 'Z') {
                if (v[i - 1] * v[i] <= 0) {
                    cnt++;
                    if (v[i-1]<=0)v[i-1]=1;
                    else v[i-1]=1;
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}
// 链接：https://ac.nowcoder.com/acm/contest/105623/C
// 来源：牛客网